home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / update-notifier / apt-cdrom-check next >
Encoding:
Text File  |  2007-04-10  |  2.2 KB  |  90 lines

  1. #!/bin/sh
  2. #
  3. # helper to check if we actually have a ubuntu CD
  4. #
  5. # Returncode:
  6. # 0 - no ubuntu CD
  7. # 1 - CD with packages 
  8. # 2 - dist-upgrader CD
  9. # 3 - addon CD
  10. # (if the returncodes change, make sure to update src/hal.c)
  11.  
  12. mount_point="$1"
  13. upgrader_dir="$mount_point/dists/stable/main/dist-upgrader/binary-all/"
  14. addon_dir="$mount_point/app-install/"
  15.  
  16. # sanity checks
  17. if [ -z "$mount_point" ]; then
  18.     exit 0
  19. fi
  20.  
  21. if [ ! -d "$mount_point/ubuntu" ]; then
  22.     exit 0
  23. fi
  24.  
  25. # check if there are "Packages" files on the cd (and ignore the 
  26. # debian-installer dir)
  27. find "$mount_point/dists/"  -name Packages|grep -q -v debian-installer
  28.  
  29. # 1 means "no lines where selected" in grep (no Packages file but the 
  30. # debian-installer ones)
  31. if [ $? -eq 1 ]; then
  32.     exit 0
  33. fi
  34.  
  35. # get some apt-config vars
  36. label_start=0
  37. cdrom_id=""
  38.  
  39. apt_dir="/"
  40. apt_state_dir="var/lib/apt/"
  41. apt_cdrom_list="cdrom.list"
  42. eval $(apt-config shell apt_dir Dir \
  43.                         apt_state_dir Dir::State \
  44.                         apt_cdrom_list Dir::State::cdroms)
  45.  
  46.  
  47.  
  48. # identifying ... [afkdsjaf] line
  49. line=$(apt-cdrom -d="$1" -m ident|grep "\[.*\]")
  50.  
  51. # remove the stuff before "Identifiyng... [dasjflkd]" -> "dasjflkd"
  52. line=${line%]*}
  53. cdrom_id=${line#*\[}
  54.  
  55. if [ -z "$cdrom_id" ]; then
  56.     # something bad happend here, we return "not yet scanned" as 
  57.     # fallback (because we are cheap)
  58.     return 1
  59. fi
  60.  
  61. # we always return ADDON cd regardless if we know it already or not
  62. # the rational is that it easier for people this way and less 
  63. # confusing
  64. if [ -d "$addon_dir" ]; then
  65.     exit 3
  66. fi
  67.  
  68. # [cdrom-id] -> cdrom-id  
  69. if grep -s -q "$cdrom_id"  $apt_dir$apt_state_dir$apt_cdrom_list; then
  70.     # already in sources.list, ignore
  71.     exit 0
  72. fi
  73.  
  74. # so this is a CD we don't know yet and it has packages. good!
  75.  
  76. # now check if it contains a signed dist-upgrader
  77. if [ -d "$upgrader_dir" ]; then
  78.     # ok, we have one, now check the authentication 
  79.     GPG="gpgv --ignore-time-conflict --keyring /etc/apt/trusted.gpg"
  80.     if $GPG $upgrader_dir/*.tar.gz.gpg $upgrader_dir/*.tar.gz; then
  81.     # verified ok, we have a valid upgrader, if it was not ok, the
  82.     # fallback to the end is ok because we still have packages on it
  83.     exit 2
  84.     fi
  85. fi
  86.  
  87. # we got a ubuntu CD with packages
  88. exit 1
  89.